package everydayone.addTwoNumber;

import primaryAlgorithm.deleteNode.ListNode;

/**
 * @Date 2020/04/14
 * @author 王光浩
 * @Thinking 暴力法（不能使用 基本数据类型来保存相应的值，会溢出）
 */
public class MyMethodOne {
	public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
		long list1 = 0;
		long list2 = 0;
		ListNode l1Node = l1;
		ListNode l2Node = l2;
		//获取 l1 的值
		while(l1Node != null) {
			list1 *= 10;
			list1 += l1Node.val;
			l1Node = l1Node.next;
		}
		//获取 l2 的值
		while(l2Node != null) {
			list2 *= 10;
			list2 += l2Node.val;
			l2Node = l2Node.next;
		}
		long tem = list1+list2;
		String s = String.valueOf(tem);
		//将结果转化为 链表
		ListNode ret = new ListNode(s.charAt(0)-'0');
		ListNode next = ret;
		for(int i = 1; i < s.length(); i++) {
			ListNode node=new ListNode(s.charAt(i)-'0');
			next.next=node;
			next=next.next;
		}
		return ret;
    }	
}
